package org.apache.servicecomb.samples.practise.houserush.user.center.aggregate;

import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author: Snake Man
 * @system:
 * @DateTime: 2022/1/1 12:35
 * @Description:
 */
@Data
@Entity
@Table(name = "houses")
@SQLDelete(sql = "update houses set deleted_at = now() where id =?")
@Where(clause = "deleted_at is null")
@EntityListeners(AuditingEntityListener.class)
public class House {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    @ManyToOne
    @JoinColumn(name = "building_id")
    private Building building;

    private String name;

    private Integer layer;

    private String state;

    private Integer sequenceInLayer;

    private BigDecimal price;

    @Temporal(TemporalType.TIMESTAMP)
    private Date deletedAt;

    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;

    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedAt;
}